﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using S4Store.Domain.NetMarketingKpi;
using LX.Web.Excel;

namespace S4Store.Domain.NetMarketingKpiReport
{
    public class NetMarketingCommonReport : ExportObject
    {

        #region 数据导出
        public override bool? Discriminate(string propertyname)
        {
            if (propertyname == "FTZXLV")
            {
                return this.FTZXLV >= this.NetMarketingStandard.FTZXLV;
            }
            if (propertyname == "DJTCLV")
            {
                return this.DJTCLV >= this.NetMarketingStandard.GZTCLV;
            }
            if (propertyname == "JKJDDiff" || propertyname == "JKJD")
            {
                return this.JKJDDiff >= 0;
            }
            if (propertyname == "XXZHLV")
            {
                return this.XXZHLV >= this.NetMarketingStandard.XXZHLV;
            }
            if (propertyname == "GZDBHLV")
            {
                return this.GZDBHLV >= this.NetMarketingStandard.GZDBHLV;
            }
            return null;
        }
        #endregion

        [Export("合计标题")]
        public virtual string HjTitle
        {
            get { return "合计"; }
        }
        public int Year { get; set; }
        public int Month { get; set; }
        public int Day { get; set; }
        public Store Store { get; set; }
        public NetMarketingKpiMonthConfig NetMarketingKpiMonthConfig { get; set; }
        public NetMarketingStandard NetMarketingStandard { get; set; }

        [Export("月度预算1", MergeVertical=true)]
        public decimal YDYS
        {
            get { return NetMarketingKpiMonthConfig.YDYS; }
        }
        /// <summary>
        /// 已经确认过月初计划
        /// </summary>
        public virtual bool IsCarKpiMonthConfigConfirmed
        {
            get
            {
                return this.NetMarketingKpiMonthConfig != null && NetMarketingKpiMonthConfig.IsConfirmed;
            }
        }
        /// <summary>
        /// 本月执行天数
        /// </summary>
        public int Days
        {
            get { return DateTime.DaysInMonth(Year, Month); }
        }

        /// <summary>
        /// 时间进度
        /// </summary>
        public decimal RateOfTime
        {
            get { return (decimal)Day * 100 / (decimal)Days; }
        }
        /// <summary>
        /// 获取信息目标
        /// </summary>
        [Export("获取信息目标")]
        public virtual int HQXXMB
        {
            get
            {
                if (NetMarketingKpiMonthConfig.SYDXSJLV == 0 || NetMarketingKpiMonthConfig.XXZHLVMB == 0) return 0;

                return (NetMarketingKpiMonthConfig.DXMB * 100 * ZJTRB / NetMarketingKpiMonthConfig.SYDXSJLV / NetMarketingKpiMonthConfig.XXZHLVMB).AutoRound();
            }
        }
        /// <summary>
        /// 获取信息目标
        /// </summary>
        public virtual int HQXXMBOfRate
        {
            get { return (RateOfTime * HQXXMB/100).AutoRound(); }
        }
        /// <summary>
        /// 月度费用
        /// </summary>
        [Export("月度费用")]
        public virtual decimal YDFY
        {
            get { return 0; }
        }
        /// <summary>
        /// 计划发帖数
        /// </summary>
        [Export("计划发帖数")]
        public virtual int JHFTS
        {
            get { return 0; }
        }
        /// <summary>
        /// 实际发帖数
        /// </summary>
        [Export("实际发帖数")]
        public virtual int FTS
        {
            get { return 0; }
        }
        /// <summary>
        /// 点击数
        /// </summary>
        [Export("点击数")]
        public virtual int DJS
        {
            get { return 0; }
        }
        /// <summary>
        /// 单击退出数
        /// </summary>
        [Export("单击退出数")]
        public virtual int DJTCS
        {
            get { return 0; }
        }
        /// <summary>
        /// 获取信息数
        /// </summary>
        [Export("获取信息数")]
        public virtual int HQXXS
        {
            get { return 0; }
        }
        /// <summary>
        /// 主动来电数
        /// </summary>
        [Export("主动来电数")]
        public virtual int ZDLDS
        {
            get { return 0; }
        }
        /// <summary>
        /// 邀约来店数
        /// </summary>
        [Export("邀约来店数")]
        public virtual int YYLDS
        {
            get { return 0; }
        }
        /// <summary>
        /// 资金投入比
        /// </summary>
        [Export("资金投入比",Format="{0}%")]
        public virtual decimal ZJTRB
        {
            get { return 0; }
        }
        /// <summary>
        /// 发帖执行率
        /// </summary>
        [Export("发帖执行率", Format = "{0}%")]
        public virtual decimal FTZXLV
        {
            get
            {
                if (JHFTS == 0) return 0;
                return (decimal)FTS * 100 / (decimal)JHFTS;
            }
        }
        /// <summary>
        /// 单击退出率
        /// </summary>
        [Export("单击退出率", Format = "{0}%")]
        public virtual decimal DJTCLV
        {
            get
            {
                if (DJS == 0) return 0;
                return (decimal)DJTCS * 100 / (decimal)DJS;
            }
        }
        /// <summary>
        /// 获取资源总数
        /// </summary>
        [Export("获取资源总数")]
        public virtual int HQZYZS
        {
            get
            {
                return ZDLDS + HQXXS;
            }
        }
        /// <summary>
        /// 获取信息比
        /// </summary>
        [Export("获取信息比", Format = "{0}%")]
        public virtual decimal HQXXB
        {
            get
            {
                return 0;
            }
        }
        /// <summary>
        /// 获得电话比
        /// </summary>
        [Export("获得电话比", Format = "{0}%")]
        public virtual decimal HDDHB
        {
            get
            {
                return 0;
            }
        }
        /// <summary>
        /// 关注度变化率
        /// </summary>
        [Export("关注度变化率", Format = "{0}%")]
        public virtual decimal GZDBHLV
        {
            get
            {
                if(DJS==0)return 0;
                return (DJS + (HQXXS - DJTCS))*100 / DJS - 100;
            }
        }

        /// <summary>
        /// 下线转化率
        /// </summary>
        [Export("下线转化率", Format = "{0}%")]
        public virtual decimal XXZHLV
        {
            get
            {
                if (HQZYZS == 0) return 0;
                return (decimal)YYLDS * 100 / (decimal)HQZYZS;
            }
        }
        /// <summary>
        /// 集客进度
        /// </summary>
        [Export("集客进度", Format = "{0}%")]
        public virtual decimal JKJD
        {
            get
            {
                if (HQXXMB == 0) return RateOfTime;
                return (decimal)HQZYZS * 100 / (decimal)HQXXMB;
            }
        }
        /// <summary>
        /// 集客进度差距
        /// </summary>
        [Export("集客进度差距", Format = "{0}%")]
        public virtual decimal JKJDDiff
        {
            get
            {
                return JKJD - RateOfTime;
            }
        }
        /// <summary>
        /// 单组资源成本
        /// </summary>
        [Export("单组资源成本", Precision=3)]
        public virtual decimal DZZYCB
        {
            get
            {
                if (HQZYZS == 0) return 0;
                return YDFY / HQZYZS;
            }
        }
    }
}
